@extends("ogreencard/layout/layout")
@section('h1',"订单管理")
@section('h2',"订单列表")
@section('content')
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5 layui-table-tool-temp">

                        <div class="layui-inline layui-show-xs-block" style="width:100px;">
                            <select class="layui-select" name="cardType">
                                <option value="">订单类型</option>
                                @foreach($types as $key => $type)
                                <option value="{{$key}}" @if($params['cardType'] == $key) selected @endif>{{$type}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <input value="{{$params['user']}}" name="user"  placeholder="用户姓名、电话" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input value="{{$params['bankManager']}}" name="bankManager"  placeholder="支行/经理" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width:100px">
                            <select name="manager">
                                <option value="">销售员</option>
                                @foreach($managers as $m)
                                <option value="{{$m->id}}">{{$m->real_name}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <input value="{{$params['exBeginDate']}}" name="exBeginDate" id="exBeginDate"  placeholder="兑换起始日期" autocomplete="off" class="layui-input" >
                        </div>

                        <div class="layui-inline layui-show-xs-block" style="width:120px">
                            <input value="{{$params['exEndDate']}}" name="exEndDate"  id="exEndDate" placeholder="兑换结束日期" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline layui-show-xs-block" style="width:120px">
                            <input value="{{$params['beginDate']}}" name="beginDate" id="beginDate"  placeholder="录入起始日期" autocomplete="off" class="layui-input" >
                        </div>

                        <div class="layui-inline layui-show-xs-block" style="width:120px">
                            <input value="{{$params['endDate']}}" name="endDate"  id="endDate" placeholder="录入结束日期" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <input type="checkbox" name="export" title="导出" class="layui-checkbox">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>


                    <div class="layui-table-tool-self">
                        <button class="layui-btn layui-btn-normal" onclick="xadmin.open('添加订单','./orderCard')"><i class="layui-icon"></i>添加</button>
                    </div>
                </div>

                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>类型</th>
                            <th>用户名</th>
                            <th>手机</th>
                            <th>收货信息</th>
                            <th>内部销售</th>
                            <th>支行/经理</th>
                            <th>产品</th>
                            <th>卡密/流水号</th>
                            <th>总积分</th>
                            <th>备注</th>
                            <th>兑换日期</th>
                            <th>录入时间</th>
                            <th>操作</th></tr>
                        </thead>
                        <tbody>
                        @foreach($orders as $order)
                        <tr>
                            {{--<td>--}}
                                {{--<input type="checkbox" name="id" value="1"   lay-skin="primary">--}}
                            {{--</td>--}}
                            <td>{{$order->order_id}}</td>
                            <td>{{$order->card_type}}</td>
                            <td>{{$order->user_name}}</td>
                            <td>{{$order->user_mobile}}</td>
                            <td>
                                {!! $order->express_user?"名字：".$order->express_user."<br/>":'' !!}
                                {!! $order->express_mobile?"电话：".$order->express_mobile."<br/>":'' !!}
                                {!! $order->express_address?"地址：".$order->express_address."<br/>":'' !!}
                                {!! $order->express_date?"时间：".$order->express_date."<br/>":'' !!}
                                {!! $order->express_company?"公司：".$order->express_company."<br/>":'' !!}
                                {!! $order->express_code?"单号：".$order->express_code."<br/>":'' !!}
                            </td>

                            <td>{{$order->saler}}</td>
                            <td>{{$order->bank."-"}}{{$order->bank_manager}}</td>
                            <td>
                                <ul>
                                    @foreach($order->goods as $g)
                                    <li>{{$g->pack_name}}【x{{$g->num}}】</li>
                                    @endforeach
                                </ul>
                            </td>
                            <td>

                                <ul>
                                    @foreach($order->cards as $c)
                                        <li>{{$c->code}} @ {{$c->pwd}}</li>
                                    @endforeach
                                </ul>

                                {{$order->pos_code}}
                            </td>
                            <td>{{$order->total_price}}</td>
                            <td style="max-width:100px;">{{$order->note}}</td>
                            <td>{{substr($order->exchange_at,0,10)}}</td>
                            <td>{{substr($order->created_at,5,11)}}</td>
                            <td class="td-manage">

                                <p class="layui-btn" onclick="xadmin.open('订单编辑','orderEdit?id={{$order->order_id}}')">
                                    <i class="layui-icon">&#xe642;</i>
                                </p>

                                <p class="layui-btn layui-btn-warm" onclick="xadmin.open('发货','orderExpress?id={{$order->order_id}}',700,500)" >发货</p>

                                <p class="layui-btn layui-btn-danger" title="删除" onclick="member_del(this,{{$order->order_id}})">删除</p>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">

                       {{$orders->appends($params)->links()}}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({elem: '#beginDate'});
        laydate.render({elem: '#endDate'});
        laydate.render({elem: '#exBeginDate'});
        laydate.render({elem: '#exEndDate'});
    });


    /*订单-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            layui.jquery.get({
                url:'./orderDel?id='+id,
                success:function(){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                fail:function(){

                }
            })

        });
    }

</script>
@endsection
